using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.Reflection;
using System.IO;

namespace Hack.DllDump
{
    public class DLL
    {
        protected ArrayList OneTypeList = new ArrayList();
        /*
         * See if we should disassemble the method source
         */
        protected bool _ShowCode = false;
        public bool ShowCode
        {
            get { return _ShowCode; }
            set { _ShowCode = value; }
        }

        public DLL(Assembly assembly)
        {
            /*
             * Navigate the types, storing pieces we want
             */
            foreach (System.Type type in assembly.GetTypes())
            {
                OneType oType = new OneType(type.FullName, type.GUID.ToString());
                OneTypeList.Add(oType);

                foreach (ConstructorInfo info in type.GetConstructors())
                {
                    oType.AddConstructor(info);
                }

                foreach (EventInfo info in type.GetEvents())
                {
                    oType.AddEvent(info);
                }

                foreach (MethodInfo info in type.GetMethods())
                {
                    oType.AddMethod(info);
                }

                foreach (MemberInfo info in type.GetMembers())
                {
                    oType.AddMember(info);
                }

                foreach (PropertyInfo info in type.GetProperties())
                {
                    oType.AddProperty(info);
                }
            }
        }

        public void ToString(StringWriter sw)
        {
            foreach (OneType o in OneTypeList)
            {
                /*
                 * Set value for whether to show IL code or not
                 */
                o.ShowCode = ShowCode;

                sw.WriteLine("==========================");
                o.ToString(sw);
            }
        }

    }
}
